﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AzaEngine
{
    public enum ScriptType
    {
        Internal = 0,
        Regexp,
        Lua
    }

    public enum ScriptReturn
    {
        None = 0,
        Success,
        Error
    }

    public class ScriptParameters
    {
        private string value;

        public string Value
        {
            get { return value; }

            set { this.value = value; }
        }

        public ScriptParameters()
        {
            Value = string.Empty;
        }

        public ScriptParameters(string value)
        {
            this.value = value;
        }

        public int GetIntValue()
        {
            int ret = 0;

            try
            {
                ret = Convert.ToInt32(Value);
            }
            catch
            { ret = 0; }

            return ret;
        }

        public bool GetBoolValue()
        {
            bool ret = false;

            try
            {
                ret = Convert.ToBoolean(Value);
            }
            catch
            {
                ret = false;

                if (Value == "1") ret = true;
            }
            return ret;
        }

        public List<string> GetListValue()
        {
            List<string> ret = new List<string>();

            try
            {
                foreach (string s in Value.Split(','))
                {
                    ret.Add(s.Trim());
                }
            }
            catch { }

            return ret;
        }
    }


    public class Script
    {
        public string ComponentId;
        public ScriptType Type;
        public ComponentType ComponentType;

        public ScriptParameters[] Parameters = new ScriptParameters[6];

        // TODO: Arrumar oe métodos para buscar o tipo de script com base nos componentes carregados
        public Script(string componentID, ScriptType type)
        {
            for (int i = 0; i < Parameters.Length; i++)
            {
                Parameters[i] = new ScriptParameters();
            }

            Parameters[0].Value = "Reserved";

            ComponentId = componentID;
            Type = type;
            ComponentType = Component.GetComponentTypeById(ComponentId);
        }

        public Script(string componentID)
            : this(componentID, ScriptType.Internal) { }

        public Script(string componentID, string par1)
            : this(componentID, ScriptType.Internal)
        {
            Parameters[1].Value = par1;
        }

        // Adiciona um script pelo Tipo de Componente (enum)
        public Script(Enum componentID)
            : this(componentID.ToString()) { }
    }
}
